import { BaseModel } from './BaseModel.js';
import { dataFiles } from '../config/database.js';

const defaultUsers = [
  {
    id: 1,
    username: 'admin',
    password: '123456',
    email: 'admin@school.edu',
    phone: '13739610307', 
    role: 'admin',
    avatar: null,
    createdAt: new Date().toISOString(),
    lastLogin: null
  },
  {
    id: 2,
    username: 'teacher1',
    password: '123456',
    email: 'teacher1@school.edu',
    phone: '13800138001',
    role: 'teacher',
    avatar: null,
    createdAt: new Date().toISOString(),
    lastLogin: null
  },
  {
    id: 3,
    username: 'student1',
    password: '123456',
    email: 'student1@school.edu',
    phone: '13800138002',
    role: 'student',
    avatar: null,
    createdAt: new Date().toISOString(),
    lastLogin: null
  },
  {
    id: 4,
    username: 'test',
    password: '123456',
    email: 'test@school.edu',
    phone: '13739610307', 
    role: 'user',
    avatar: null,
    createdAt: new Date().toISOString(),
    lastLogin: null
  }
];

export class User extends BaseModel {
  constructor() {
    super(dataFiles.users, defaultUsers);
  }

  findByUsername(username) {
    return this.findOne({ username });
  }

  findByPhone(phone) {
    return this.findOne({ phone });
  }

  updateLastLogin(id) {
    return this.update(id, { lastLogin: new Date().toISOString() });
  }
}